SUBROUTINE objfcn(p, fval)
  USE commonvars
  IMPLICIT NONE

  REAL(8), INTENT(IN)     :: p(:)
  REAL(8), INTENT(OUT)    :: fval
  INTEGER                 :: n 

  EXTERNAL moments
  
  n=size(p, dim=1)

  CALL moments(n, p, fval)
  
END SUBROUTINE objfcn
